<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="edu.colorado.csci3308.ekwhite.code.FaceCard" %>
<%@ page import="edu.colorado.csci3308.ekwhite.code.StudentsInCourse" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Wonderful, magical flashcards</title>
</head>
<body>
<% 	StudentsInCourse cardList = (StudentsInCourse) request.getSession(true).getAttribute("currentCardList");
	Integer currentCard = (Integer) request.getSession(true).getAttribute("currentCard");
	if (cardList == null)	
	{
		cardList = new StudentsInCourse();
		cardList.createDefaultList();
		currentCard = 0;
	} 
	// currentCard can start out at weird initial values, so we kick it into a usable range
	if (currentCard == null)
		currentCard = 0;
	if (currentCard > 3)
		currentCard %= 4;
	while (currentCard < 0) 
	{
		currentCard += 4;
	}
		
	request.getSession(true).setAttribute("currentCard", currentCard);
	request.getSession(true).setAttribute("cardList", cardList);
	
	if (currentCard >= 0 && currentCard < cardList.getMasterList().size())
	{
		out.println(cardList.getMasterList().get(currentCard).toString()); 
		out.println("<br><img src=\"" + this.getClass().getResource("/" + cardList.getMasterList().get(currentCard).getPhotoFile()) + "\"/>");
	//	out.println("<br><img src=\"reptiles/" + cardList.getMasterList().get(currentCard).getPhotoFile()) + "\"/>");		
	} %>
 	


	<% if (currentCard < cardList.getMasterList().size() - 1)  { %> 
	<FORM action="/FaceLearner1/AdvanceCardServlet" method="post"> 
	<br>
	<INPUT type="submit" name="Submit" value="Next Card">
	</FORM>
	<% } if (currentCard > 0) { %> 
	<FORM action="/FaceLearner1/BackwardCardServlet" method="post">
	<br>
	<INPUT type="submit" name="Submit" value="Previous Card">
	</FORM>
	<% } %>
	
</body>
</html>